#!/usr/bin/env bash
STATUS=$(awk '/%/ {gsub(/[\[\]]/,""); print $6}' <(amixer sget Master) | awk 'FNR == 1')
toggle() {
    if [ $STATUS == "on" ]; then
        amixer set Master toggle
        notify-send --icon=volume-level-muted --urgency=normal "Volume " "Volume has been muted!"
    else
        amixer set Master toggle
        notify-send --icon=volume-level-high --urgency=normal "Volume" "Volume has been unmuted!"
    fi
}

icon() {
    #             
    if [ $STATUS == "on" ]; then
        # echo ""
        vol=$(amixer sget Master | awk -F'[][]' '/Right:|Mono:/ && NF > 1 {sub(/%/, ""); printf "%0.0f\n", $2}')
        # -eq 等于 -lt 小于 -ne 不等于 -gt 大于 -le 小于等于 -ge 大于等于
        if [[ "${vol}" -ge 80 ]]; then
            echo ""
        elif [[ "${vol}" -ge 40 ]]; then
            echo "奔"
        elif [[ "${vol}" -ge 10 ]]; then
            echo ""
        else
            echo ""
        fi
    else
        echo ""
    fi
}

status() {
    if [ $STATUS == "on" ]; then
        echo "On"
    else
        echo "Off"
    fi
}

setting() {
    # cd $HOME
    # eww close-all
    eww --config ${HOME}/.dwm/scripts/config/eww close-all
    pavucontrol &
}

if [[ $1 == "--toggle" ]]; then
    toggle
elif [[ $1 == "--icon" ]]; then
    icon
elif [[ $1 == "--status" ]]; then
    status
elif [[ $1 == "--setting" ]]; then
    setting
fi
